<?php

/**
 * Created by PhpStorm.
 * User: 何婷婷
 * Date: 2016/11/12
 * Time: 12:07
 */

abstract class ParamHandler {
    protected $source;
    protected $params =array();

    function __construct($source)
    {
        $this->source=$source;
    }

    function addParam($key,$val){
        $this->addParam[$key]=$val;
    }

    function getAllParam(){
        return $this->params;
    }

    static function getInstance($filename) {
        if (preg_match("/\.xml$/i",$filename)) {
            return new XmlParamHandler($filename);
        }
        return new TextParamhandler($filename);
    }
    abstract function write();
    abstract function read();
}

class XmlParamHandler extends ParamHandler {
    function read()
    {
        // TODO: Implement read() method.
    }
    function write()
    {
        // TODO: Implement write() method.
    }
}

class TexparamHandler extends ParamHandler {
    function read()
    {
        // TODO: Implement read() method.
    }

    function write()
    {
        // TODO: Implement write() method.
    }
}

$test=ParamHandler::getInstance("./params.xml");
$test->addParam("key1","val");
$test->addParam("key2","val2");
$test->addParam('key3','val3');
$test->write();
$test=ParamHandler::getInstance("./params.txt");
$test->read();
